package com.jtny.nytb.config.dictionary.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.jtny.component.entity.WebResponse;
import com.jtny.nytb.config.dictionary.service.DictionaryDataBiz;
import com.jtny.nytb.config.dictionary.vo.DictionaryDataVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 数据字典项Controller类
 *
 * @author 智慧能源中心-lyq
 * @version 1.0
 * @package com.jtny.nytb.config.dictionary.controller
 * @fileName DictionaryDataController.java
 * @createTime 2023年09月01日 11:15
 * @Copyright© 2023 jtny
 * 江投能源技术研究院 版权所有
 */
@RestController
@Api(value = "数据字典项管理", tags = "数据字典项管理")
@RequestMapping("/config/dictionaryData")
public class DictionaryDataController {

    @Autowired
    private DictionaryDataBiz dictionaryDataBiz;

    private static final String OPER_SUCCESS_MESSAGE = "操作成功！";

    @ApiOperation("数据字典项新增操作")
    @ApiImplicitParam(name = "dictionaryDataVO", value = "数据字典项新增操作", required = true, paramType = "query", dataType = "DictionaryDataVO")
    @ApiOperationSupport(order = 1)
    @PostMapping("/save")
    @ResponseBody
    public WebResponse<?> saveDictionaryData(@RequestBody @Valid DictionaryDataVO dictionaryDataVO) {
        DictionaryDataVO dictionaryData = dictionaryDataBiz.saveDictionaryData(dictionaryDataVO);
        return WebResponse.success(OPER_SUCCESS_MESSAGE, dictionaryData);
    }

    @ApiOperation("数据字典项更新操作")
    @ApiImplicitParam(name = "dictionaryDataVO", value = "数据字典项更新操作", required = true, paramType = "query", dataType = "DictionaryDataVO")
    @ApiOperationSupport(order = 2)
    @PutMapping("/update")
    @ResponseBody
    public WebResponse<?> updateDictionaryData(@RequestBody @Valid DictionaryDataVO dictionaryDataVO) {
        dictionaryDataBiz.updateDictionaryData(dictionaryDataVO);
        return WebResponse.success(OPER_SUCCESS_MESSAGE);
    }

    @ApiOperation("数据字典项查看操作")
    @ApiImplicitParam(name = "dictionaryDataId", value = "数据字典项id", required = true, paramType = "path")
    @ApiOperationSupport(order = 3)
    @GetMapping("/detail/{dictionaryDataId}")
    @ResponseBody
    public WebResponse<?> detailDictionaryData(@PathVariable("dictionaryDataId") Long dictionaryDataId) {
        DictionaryDataVO dictionaryDataVO = dictionaryDataBiz.detailDictionaryData(dictionaryDataId);
        return WebResponse.success(dictionaryDataVO);
    }

    @ApiOperation("删除数据字典项")
    @ApiImplicitParam(name = "id", value = "数据字典项id", required = true, paramType = "path")
    @ApiOperationSupport(order = 4)
    @GetMapping("/delete/{id}")
    @ResponseBody
    public WebResponse<?> deleteDictionary(@PathVariable("id") Long id) {
        dictionaryDataBiz.deleteDictionaryData(id);
        return WebResponse.success(OPER_SUCCESS_MESSAGE);
    }
}
